<?php

class common extends CI_Model {

	public function __construct()
	{
		$this->load->database();
	}
	
	public function get_all_track(){
            //$this->input->post('title')
            $query = $this->db->query("SELECT * FROM tbl_tracks ORDER BY id DESC");
            return $query->result_array();
	}
        
	public function get_track($id){            
            $query = $this->db->query("SELECT * FROM tbl_tracks where id=$id");            
            $return =  $query->result_array();
            return $return[0];            
	}
        
        public function add_bill(){
            
            $bill_number =  $this->input->post('bill_number');
            $origin =  $this->input->post('origin');            
            $destination =  $this->input->post('destination');
            $container_id = addslashes($this->input->post('container_id'));
            $bill_of_lading =  $this->input->post('bill_of_lading');            
            $shipper =  $this->input->post('shipper');
            $consignee =  $this->input->post('consignee');
            $consignor =  $this->input->post('consignor');
            $containers_no =  $this->input->post('containers_no');
            $weight =  $this->input->post('weight');
            $rar =  $this->input->post('rar');
            $duty =  $this->input->post('duty');
            $edd =  $this->input->post('edd');
            $editid =  $this->input->post('editid');
            
            if(!empty($editid))
            {
                $query = "Update tbl_tracks set bill_number='".$bill_number."',origin='".$origin."', destination='".$destination."',container_id='".$container_id."',
                bill_of_lading='".$bill_of_lading."',shipper='".$shipper."',consignee='".$consignee."',consignor='".$consignor."',containers_no='".$containers_no."',
                    weight='".$weight."',rar='".$rar."',duty='".$duty."',edd='".$edd."' where id=$editid";
                $this->db->query($query);
            }else{
                $query = "INSERT INTO tbl_tracks (bill_number,origin,destination,container_id,bill_of_lading,shipper,consignee,consignor,containers_no,weight,
                        rar,duty,edd,status) 
                VALUES  ('".$bill_number."','".$origin."','".$destination."','".$container_id."','".$bill_of_lading."','".$shipper."','".$consignee."','".$consignor."',
                            '".$containers_no."','".$weight."','".$rar."','".$duty."','".$edd."',1)";
                $this->db->query($query);
            }               
        }
	
        public function get_all_status(){            
            $query = $this->db->query("SELECT * FROM tbl_status ORDER BY id ");
            return $query->result_array();
	}
        
        public function get_status($id){            
            $query = $this->db->query("SELECT * FROM tbl_status where id=$id");
            $return =  $query->result_array();
            return $return[0];            
	}
        
        
        public function add_bill_status(){
            
            $bill_number =  $this->input->post('bill_number');
            $status =  $this->input->post('status');
            $location =  $this->input->post('location');
            $sdate = addslashes($this->input->post('sdate'));
            $t_hour =  $this->input->post('t_hour');
            $t_min =  $this->input->post('t_min');
            $editid =  $this->input->post('editid');
			            
            if(!empty($editid))
            {
                $query = "Update tbl_status set bill_number='".$bill_number."',status='".$status."', location='".$location."',sdate='".$sdate."',t_hour='".$t_hour."'
						,t_min='".$t_min."' where id=$editid";
                $this->db->query($query);
				
            }else{
                $query = "INSERT INTO tbl_status (bill_number,status,location,sdate,t_hour,t_min) 
                VALUES  ('".$bill_number."','".$status."','".$location."','".$sdate."','".$t_hour."','".$t_min."')";
                $this->db->query($query);
            }               
        }
        
        
        
        
        
        
        
        
        
        
	public function get_qualifications(){
		$query = $this->db->query("SELECT * FROM `qualifications` WHERE qualif_status = 1 ORDER BY ordering ");
		return $query->result_array();
	}
	
	public function get_cities_of_country($country_id){
		$query = $this->db->query("SELECT * FROM `cities` WHERE country_id = ".$country_id." ORDER BY city_name ");
		return $query->result_array();
	}
	
	public function get_active_packages(){
		$query = $this->db->query("SELECT * FROM `user_level` WHERE level_status = 1 ORDER BY level_order ");
		return $query->result_array();
	}
}

?>